package com.ydc.controller;

import com.ydc.pojo.Bill;
import com.ydc.pojo.PageResult;
import com.ydc.service.BillService;
import com.ydc.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/bill")
public class BillController {

    @Autowired
    private BillService billService;

    @GetMapping("/getuserbill")
    public SysResult getuserbill( PageResult pageResult) {
        pageResult = billService.getuserbill(pageResult);
        return SysResult.success(pageResult);
    }

    @GetMapping("/list")
    public SysResult findBillByPage(PageResult pageResult){//只有3个参数
        //携带所有的数据返回
        pageResult = billService.findBillByPage(pageResult);
        return SysResult.success(pageResult);
    }

    @PostMapping("/addBill")
    public SysResult addBill(@RequestBody Bill bill){
        billService.addBill(bill);
        return SysResult.success();
    }

    @PutMapping("/status/{id}/{status}")
    public SysResult updateBillStatus(Bill bill){
        billService.updateBillStatus(bill);
        return SysResult.success();
    }

    @DeleteMapping("/deleteBillById")
    public SysResult deleteBillById(Bill bill){
        billService.deleteBillById(bill);
        return SysResult.success();
    }

    @PutMapping("/updateBill")
    public SysResult updateBill(@RequestBody Bill bill){
        billService.updateBill(bill);
        return SysResult.success();
    }
}
